import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:maihealth/utils/animationRoute.dart';
import 'dart:io';
class Router{
 //全局上下文
 static BuildContext gloabContext;

 SlideTransition createTransition(
  Animation<double> animation, Widget child) {
    return new SlideTransition(
        position: new Tween<Offset>(
        begin: const Offset(1.0, 0.0),
        end: const Offset(0.0, 0.0),
    ).animate(animation),
        child: child,
    );
}

//动态路由
static void push(BuildContext context,Widget widget){
      if (Platform.isIOS) {
        print('IOS');
           Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) => widget));
      } else {
          print('Android');
           Navigator.push(context, new CupertinoPageRoute(builder: (BuildContext context) => widget));
      }
  }

  //modal页面  fullscreenDialog决定是modal还是pop
 static void modal(BuildContext context,Widget widget){
      Navigator.push(context, new CupertinoPageRoute(builder: (BuildContext context) => widget,fullscreenDialog: true));
  }
  //返回上一级
 static void pop(BuildContext context){
      Navigator.pop(context);
  }



  //切换跟页面
 static void changeRootPage(BuildContext context,Widget widget){
   BuildContext current_context = context == null ? gloabContext : context;
   Navigator.of(current_context).pushAndRemoveUntil(
      Platform.isIOS ?  new MaterialPageRoute(builder: (current_context) => widget) : new CupertinoPageRoute(builder: (current_context) => widget)
        // animationRoute(widget)//自定义转场动画,取消push动画效果
      , (route) => route == null);
  }
}